<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link type="text/css" rel="stylesheet" href="css/qingkuang.css">
</head>
<body style="width: 100%;height: 100%">
<div class="qkc_out">
    <div class="qkc">
<!--        搜索框-->
        <div style="padding-top: 20px">
            <input id="usernamex" type="text" class="i1" placeholder="请输入报销人、报销时间" style="height: 34px;width: 280px;margin-left: 60px">
            <input id="starttime" type="date" class="i1" placeholder="开始日期" style="height: 34px;width: 120px;margin-left: 20px">&nbsp;-
            <input id="endtime" type="date" class="i1" placeholder="结束日期" style="height: 34px;width: 120px">
            <input onclick="chaxun()" class="i1" value="查询" type="button" style="height: 34px;width: 80px;border: #216DF5 solid 1px;background-color: #E9F3FE;color: #216DF5">
            <input onclick="chongzhi()" class="i1" value="重置" type="button" style="height: 34px;width: 80px;border: #216DF5 solid 1px;background-color: #8F9292;color: white">
            <button class="i1" id="adddatabutton" onclick="adddata()" style="height: 34px;width: 80px;margin-right: 60px;float: right;border: #216DF5 solid 1px;background-color: #E9F3FE;color: #216DF5">添加数据</button>
        </div>
<!--        添加数据弹出框-->
        <div class="adddata"></div>
<!--        收支情况表单-->
        <div class="adddataform">
            <div style="width: 100%;height: 26px"><a onclick="adddataclose()" style="float: right;color: #8F9292;margin-right: 5px;" href="#">✕</a></div>
            <div style="width: 100%;height: 32px;margin-top: 10px;text-align: center">
                <span style="color: #2D2F33;font-size: 22px;font-weight: bolder;">添加新数据</span>
            </div>
            <div class="div2">
                <span class="dataitemtile">报销人:</span>
                <select id="bxrselect" class="datainfor">
<!--                    <option selected="selected" value="1">团队</option>-->
                </select>
            </div>
            <div class="div2">
                <span class="dataitemtile">报销事由:</span>
                <input id="reason" class="datainfor" placeholder="请输入事由:">
            </div>
            <div class="div2">
                <span class="dataitemtile">收入/支出时间:</span>
                <input id="createTime" type="date" class="datainfor" placeholder="请输入收入/支出时间:">
            </div>
            <div class="div2">
                <span class="dataitemtile">收支金额:</span>
                <input id="sum" class="datainfor" placeholder="请输入收支金额:">
            </div>
            <div class="div2">
                <span class="dataitemtile">报销类型:</span>
                <select id="type" class="datainfor">
                    <option value="1">支出</option>
                    <option value="2">收入</option>
                </select>
            </div>
            <div class="div2">
                <span class="dataitemtile">报销日期:</span>
                <input id="reasontime" type="date" class="datainfor" placeholder="请输入时间:">
            </div>
            <div class="div2">
                <button onclick="submitadd()" class="button1" style="margin-left: 160px;float: left">确定</button>
                <button onclick="adddataclose()" class="button1" style="margin-right: 160px;float: right">取消</button>
            </div>
        </div>
<!--        表格-->
        <table id="dongtaibiao" style="margin-left: 60px;margin-right: 60px;border-collapse : collapse;margin-top: 20px;table-layout : fixed">
                <tr class="tabhead" style="font-size: 16px;color: #A08D99;font-weight: 500;height: 50px;background-color: #ECF1F9;">
                    <td style="width: 100px;text-align: center;">
                        <span>
                            报销人
                            <div style="margin-left: 100px;margin-top: -16px">
                            <div onclick="bxrup()" class="up" id="bxrup"></div>
                                <div style="height: 2px"></div>
                            <div onclick="bxrdown()" class="down" id="bxrdown"></div>
                            </div>
                        </span>
                    </td>
                    <td style="width: 120px;text-align: center">事由</td>
                    <td style="width: 150px;text-align: center">收入/支出时间</td>
                    <td style="width: 100px;text-align: center">收支金额</td>
                    <td style="width: 100px;text-align: center">类型</td>
                    <td style="width: 100px;text-align: center">剩余金额</td>
                    <td style="width: 100px;text-align: center">记录人</td>
                    <td style="width: 150px;text-align: center">
                        <span>
                            报销时间
                            <div style="margin-left: 150px;margin-top: -16px">
                            <div onclick="bxtup()" class="up" id="bxtup"></div>
                                <div style="height: 2px"></div>
                            <div onclick="bxtdown()" class="down" id="bxtdown"></div>
                            </div>
                        </span>
                    </td>
                    <td style="width: 120px;text-align: center">操作</td>
                </tr>
        </table>
        <div id="page" style="margin-top: 10px">
            <div style="margin-left: 60px;height: 26px;width: 500px;float: left">
                共<span id="itemtotal">83</span>条记录，当前显示第<span id="itemstart">76</span>-<span id="itemend">83</span>条
                <select>
                    <option selected="selected">15条/页</option>
                    <option>20条/页</option>
                </select>
            </div>
            <div class="pagebutton">
                <div id="perfix" class="pbtp">
                    <a href="#"><</a>
                </div>
                <div class="pbtt" style="width: 50px;height: 22px;color: #A08D99">
                </div>
                <div id="next" class="pbtp">
                    <a href="#">></a>
                </div>
            </div>
        </div>
        <div style="height: 2px;background-color: #B4BCCC;margin-left: 40px;margin-right: 40px;margin-top: 40px"></div>
    </div>
</div>
</body>
<script>
    //收支情况数据列表
    var shouzhis=[
        {
            baoxiaoren: '团队',
            shiyou: '测试',
            shouzhit: '2018-05-08',
            shouzhip: '100',
            type: '支出',
            yue: '7113.39',
            jiluren: '张三',
            baoxiaot: '2018-05-08'
        },
        {
            baoxiaoren: '团队',
            shiyou: '测试',
            shouzhit: '2018-03-18',
            shouzhip: '49',
            type: '支出',
            yue: '7213.39',
            jiluren: '张三',
            baoxiaot: '2018-03-18'
        },
        {
            baoxiaoren: '团队',
            shiyou: '测试',
            shouzhit: '2018-03-18',
            shouzhip: '49',
            type: '支出',
            yue: '7213.39',
            jiluren: '张三',
            baoxiaot: '2018-03-18'
        },
        {
            baoxiaoren: '团队',
            shiyou: '测试',
            shouzhit: '2018-03-18',
            shouzhip: '49',
            type: '支出',
            yue: '7213.39',
            jiluren: '张三',
            baoxiaot: '2018-03-18'
        },
        {
            baoxiaoren: '团队',
            shiyou: '测试',
            shouzhit: '2018-03-18',
            shouzhip: '49',
            type: '支出',
            yue: '7213.39',
            jiluren: '张三',
            baoxiaot: '2018-03-18'
        },
        {
            baoxiaoren: '团队',
            shiyou: '测试',
            shouzhit: '2018-03-18',
            shouzhip: '49',
            type: '支出',
            yue: '7213.39',
            jiluren: '张三',
            baoxiaot: '2018-03-18'
        },
        {
            baoxiaoren: '团队',
            shiyou: '测试',
            shouzhit: '2018-03-18',
            shouzhip: '49',
            type: '支出',
            yue: '7213.39',
            jiluren: '张三',
            baoxiaot: '2018-03-18'
        },
        {
            baoxiaoren: '团队',
            shiyou: '测试',
            shouzhit: '2018-03-18',
            shouzhip: '49',
            type: '支出',
            yue: '7213.39',
            jiluren: '张三',
            baoxiaot: '2018-03-18'
        }
    ]
    //编辑数据时用到的临时对象
    var edittem={
        baoxiaoren: '',
        shiyou: '',
        shouzhit: '',
        shouzhip: '',
        type: '',
        yue: '',
        jiluren: '',
        baoxiaot: ''
    }

    //当前页
    var current=1
    //总个数
    var total=0
    //总页数
    var totalpage=0
    //每页个数
    var limit=8
    //编辑flag
    var flag=null

    //收支情况条件
    var financequeryvo={
        current: 1,
        endtime: null,
        index: "",
        limit: 8,
        starttime: null,
        username: ""
    }
    //新增数据用到的系统用户列表
    var users=null
    //
    var tbFinanceInfo={
        claimerUserId: null,
        createTime: null,
        reason: "",
        reasonTime: null,
        recorderUserId: null,
        sum: "",
        type: 2
    }


    //编辑
    function edit(val){
        if(flag===null){
            flag=val
            if(val%2==0){//颜色变化
                $("#"+val).replaceWith("<tr class='d1' id='tempid' class=\"tabhead\" style=\"font-size: 14px;color: #2D2F33;\n" +
                    "                font-weight: 500;height: 50px;\n" +
                    "                background-color: #FFFFFF;\">\n" +
                    "                <td style=\"width: 100px;\">\n" +
                    // "                    <input type='text' style='width: 80px;height: 26px;'>\n" +
                        "<select style='width: 80px;height: 26px;'><option selected='selected'>团队</option></select>"+
                    "                </td>\n" +
                    "                <td style=\"width: 120px;\">\n" +
                    "                    <input style='width: 100px;height: 26px;'>\n" +
                    "                </td>\n" +
                    "                <td style=\"width: 150px;\">\n" +
                    "                    <input style='width: 100px;height: 26px'>\n" +
                    "                </td>\n" +
                    "                <td style=\"width: 100px;\">\n" +
                    "                    <input style='width: 70px;height: 26px'>\n" +
                    "                </td>\n" +
                    "                <td style=\"width: 100px;\">\n" +
                    // "                    <input style='width: 70px;height: 26px'>\n" +
                        "<select style='width: 70px;height: 26px'><option selected='selected'>支出</option><option>收入</option></select>"+
                    "                </td>\n" +
                    "                <td style=\"width: 100px;text-align: center\">" + shouzhis[i].yue + "</td>\n" +
                    "                <td style=\"width: 100px;text-align: center\">" + shouzhis[i].jiluren + "</td>\n" +
                    "                <td style=\"width: 150px;\">\n" +
                    "                    <input style='width: 100px;height: 26px'>\n" +
                    "                </td>\n" +
                    "                <td style=\"width: 120px;text-align: center\">\n" +
                    "                    <button  style=\"text-decoration: none;color: white;background-color: #2985F7;border-radius: 4px\" onclick=\"okk()\">确认</button>&nbsp;&nbsp;\n" +
                    "                    <button  style=\"text-decoration: none;border-radius: 4px\">取消</button>\n" +
                    "                </td>\n" +
                    "            </tr>")
            }else {
                $("#"+val).replaceWith("<tr class='d1' id='tempid' class=\"tabhead\" style=\"font-size: 14px;color: #2D2F33;\n" +
                    "                font-weight: 500;height: 50px;\n" +
                    "                background-color: #F4F7FD;\">\n" +
                    "                <td style=\"width: 100px;\">\n" +
                    // "                    <input type='text' style='width: 80px;height: 26px;'>\n" +
                    "<select style='width: 80px;height: 26px;'><option selected='selected'>团队</option></select>"+
                    "                </td>\n" +
                    "                <td style=\"width: 120px;\">\n" +
                    "                    <input style='width: 100px;height: 26px;'>\n" +
                    "                </td>\n" +
                    "                <td style=\"width: 150px;\">\n" +
                    "                    <input style='width: 100px;height: 26px'>\n" +
                    "                </td>\n" +
                    "                <td style=\"width: 100px;\">\n" +
                    "                    <input style='width: 70px;height: 26px'>\n" +
                    "                </td>\n" +
                    "                <td style=\"width: 100px;\">\n" +
                                       "<select style='width: 70px;height: 26px'><option selected='selected'>支出</option><option>收入</option></select>"+
                    "                </td>\n" +
                    "                <td style=\"width: 100px;text-align: center\">" + shouzhis[i].yue + "</td>\n" +
                    "                <td style=\"width: 100px;text-align: center\">" + shouzhis[i].jiluren + "</td>\n" +
                    "                <td style=\"width: 150px;\">\n" +
                    "                    <input style='width: 100px;height: 26px'>\n" +
                    "                </td>\n" +
                    "                <td style=\"width: 120px;text-align: center\">\n" +
                    "                    <button  style=\"text-decoration: none;color: white;background-color: #2985F7;border-radius: 4px\" onclick=\"okk()\">确认</button>&nbsp;&nbsp;\n" +
                    "                    <button  style=\"text-decoration: none;border-radius: 4px\">取消</button>\n" +
                    "                </td>\n" +
                    "            </tr>")
            }
        }


    }
    function edit1(financeinfo){
        if(flag!=null){
            return false
        }
        flag=financeinfo.id
        console.log("测试编辑提交参数:",financeinfo)
        $("#"+financeinfo.id+" td").remove()//移除原来的元素
        //加入新的编辑元素
        $("#"+financeinfo.id).append(
            "                <td style=\"width: 100px;\">\n" +
            // "                    <input type='text' style='width: 80px;height: 26px;'>\n" +
            "<select id='editbxrselect' style='width: 80px;height: 26px;'></select>"+
            "                </td>\n" +
            "                <td style=\"width: 120px;\">\n" +
            "                    <input id='editshiyou' style='width: 100px;height: 26px;'>\n" +
            "                </td>\n" +
            "                <td style=\"width: 130px;\">\n" +
            "                    <input type='date' id='editszt' style='width: 130px;height: 26px;'>\n" +
            "                </td>\n" +
            "                <td style=\"width: 100px;\">\n" +
            "                    <input id='editsum' style='width: 70px;height: 26px'>\n" +
            "                </td>\n" +
            "                <td style=\"width: 80px;\">\n" +
            "<select id='edittype' style='width: 80px;height: 26px'><option value='1'>支出</option><option value='2'>收入</option></select>"+
            "                </td>\n" +
            "                <td style=\"width: 100px;text-align: center\">" + financeinfo.balance + "</td>\n" +
            "                <td style=\"width: 100px;text-align: center\">" + financeinfo.recorderuname + "</td>\n" +
            "                <td style=\"width: 130px;\">\n" +
            "                    <input type='date' id='recoredt' style='width: 130px;height: 26px'>\n" +
            "                </td>\n" +
            "                <td style=\"width: 120px;text-align: center\">\n" +
            "                    <button  style=\"text-decoration: none;color: white;background-color: #2985F7;border-radius: 4px\" onclick='okk("+JSON.stringify(financeinfo)+
            ")'>确认</button>&nbsp;&nbsp;\n" +
            "                    <button onclick='flagtonull()'"+
            "  style=\"text-decoration: none;border-radius: 4px\">取消</button>\n" +
            "                </td>")
        $("#editshiyou").val(financeinfo.reason)
        $("#editszt").val(financeinfo.zhifutime.substring(0,10))
        $("#editsum").val(financeinfo.sumx)
        $("#recoredt").val(financeinfo.reasontime.substring(0,10))
        //获取报销人列表 并且默认选中当前
        $.ajax({//GET请求通过用户id 获取用户信息
            url: ppath+"getalluser",
            type: "GET",
            async: false,
            dataType: "text",
            success: function (result) {
                users=JSON.parse(result)
                console.log('用户列表',users)
            },
            error: function (res){//请求异常时的回调
                alert("没有该用户")
            }
        });
        for(var i=0;i<users.length;i++){
            if(users[i].type==1){
                $("#editbxrselect").append("<option id='editbxroptions' value='" +users[i].id+
                    "' >" +users[i].userName+ "</option>")
            }
        }
        $("#editbxrselect option[value='"+financeinfo.claimeruid+"']").prop("selected",true)
        //默认选中当前收支类型
        $("#edittype option[value='"+financeinfo.typex+"']").prop("selected",true)


    }
    function deletex(id){
        if(window.confirm("删除后不可恢复！您确定删除吗？")){
            console.log("确认删除",id)
            // 一下为删除操作
            $.ajax({//GET请求通过用户id 获取用户信息
                url: ppath+"deletefinanceinfo/"+id,
                type: "GET",
                async: false,
                dataType: "text",
                success: function (result) {
                    if(result){
                        alert("删除成功")
                        loaddata()
                        makepages()
                    }
                },
                error: function (res){//请求异常时的回调
                    alert("删除失败")
                }
            });
        }else {
            alert("您已经取消删除")
        }
    }
    //取消编辑
    function flagtonull(){
        flag=null
        loaddata()
    }
    //确认编辑
    function okk(financeinfo){
        var tbFinanceInfo1={
            id:null,
            claimerUserId: null,
            createTime: null,
            reason: "",
            reasonTime: null,
            recorderUserId: null,
            sum: "",
            type: 2
        }
        flag=null
        tbFinanceInfo1.id=financeinfo.id
        tbFinanceInfo1.claimerUserId=$("#editbxrselect").find("option:selected").val()
        tbFinanceInfo1.reason=$("#editshiyou").val()
        tbFinanceInfo1.createTime=$("#editszt").val()
        tbFinanceInfo1.sum=$("#editsum").val()
        tbFinanceInfo1.type=$("#edittype").find("option:selected").val()
        tbFinanceInfo1.reasonTime=$("#recoredt").val()
        tbFinanceInfo1.recorderUserId=$.cookie('userid')
        if(tbFinanceInfo1.createTime==''){
            alert("请输入收入/支出时间")
            return false
        }
        if(tbFinanceInfo1.reasonTime==''){
            alert("请输入报销时间")
            return false
        }
        if(tbFinanceInfo1.reason==''){
            alert("请输入报销事由")
            return false
        }
        if(tbFinanceInfo1.sum==''){
            alert("请输入报销金额")
            return  false
        }
        console.log("测试编辑提交的参数：",tbFinanceInfo1)
        $.ajax({
            url: ppath+"updatafinanceinfo",
            type: "POST",
            async: false,
            contentType:"application/json;charset=UTF-8",
            data: JSON.stringify(tbFinanceInfo1),
            // data: user,
            dataType: "text",
            success: function (result) {
                if(result){//添加成功
                    financequeryvo.current=1
                    loaddata()
                    makepages()
                    alert("编辑成功")


                }
            },
            error: function (res){
                // alert("网络错误")
            }
        })



        //移除标签
        // $(".d1").remove()
        //
        // // $("#tempid").remove()
        // loaddata()
    }
    //查询
    function chaxun(){
        financequeryvo.current=1
        financequeryvo.username=$("#usernamex").val()
        // financequeryvo.username="六"
        financequeryvo.starttime=$("#starttime").val()
        financequeryvo.endtime=$("#endtime").val()
        console.log('测试分页查询条件的提交：',financequeryvo)
        loaddata()
        makepages()
    }
    //重置
    function chongzhi(){
        // financequeryvo.current=1
        financequeryvo.username=""
        financequeryvo.starttime=null
        financequeryvo.endtime=null
        $("#usernamex").prop("value","")
        $("#starttime").prop("value",null)
        $("#endtime").prop("value",null)
    }
    //报销人
    function bxrup(){
        $("#bxrup").css("border-bottom","6px solid #2985F7")
        $("#bxrdown").css("border-top","6px solid #B4BCCC")
        $("#bxtup").css("border-bottom","6px solid #B4BCCC")
        $("#bxtdown").css("border-top","6px solid #B4BCCC")
        financequeryvo.index="uasc"
        loaddata()
        makepages()
    }
    function bxrdown(){
        $("#bxrdown").css("border-top","6px solid #2985F7")
        $("#bxrup").css("border-bottom","6px solid #B4BCCC")
        $("#bxtup").css("border-bottom","6px solid #B4BCCC")
        $("#bxtdown").css("border-top","6px solid #B4BCCC")
        financequeryvo.index="udesc"
        loaddata()
        makepages()
    }
    //报销时间
    function bxtup(){
        $("#bxtup").css("border-bottom","6px solid #2985F7")
        $("#bxtdown").css("border-top","6px solid #B4BCCC")
        $("#bxrup").css("border-bottom","6px solid #B4BCCC")
        $("#bxrdown").css("border-top","6px solid #B4BCCC")
        financequeryvo.index="tasc"
        loaddata()
        makepages()
    }
    function bxtdown(){
        $("#bxtdown").css("border-top","6px solid #2985F7")
        $("#bxtup").css("border-bottom","6px solid #B4BCCC")
        $("#bxrup").css("border-bottom","6px solid #B4BCCC")
        $("#bxrdown").css("border-top","6px solid #B4BCCC")
        financequeryvo.index="tdesc"
        loaddata()
        makepages()
    }
    $(document).ready(function(){
        $("#adddatabutton").after(function (){
            //遍历数据生成表格
            loaddata()
            //生成分页插件
           makepages()
        })
        //上一页
        $("#perfix").click(function (){
            prefix()
        })
        //下一页
        $("#next").click(function (){
            nextp()
        })
    });
    //公共方法
    function loaddata(){
        //查询条件
        var  financeinfo=null;


        //ajax获取list收支数据
        $.ajax({
            url: ppath+"queryinfo",
            type: "POST",
            async: false,
            contentType:"application/json;charset=UTF-8",
            data: JSON.stringify(financequeryvo),
            // data: user,
            dataType: "text",
            success: function (result) {
                financeinfo=JSON.parse(result)
                console.log('测试收支列表：',financeinfo)
            },
            error: function (res){
                // alert("网络错误")
            }
        })
        $(".d1").remove()
            //遍历数据生成表格
            for(i=0;i<financeinfo.length;i++) {
                //白背景
                if (i % 2 == 0) {
                    $("#dongtaibiao").append("<tr class='d1' style=\"font-size: 14px;color: #2D2F33;\n" +
                        "                font-weight: 500;height: 50px;\n" +
                        "                background-color: #FFFFFF;\"" +
                        " id='" + financeinfo[i].id + "'" + ">\n" +
                        "                <td style=\"width: 100px;text-align: center\">" + financeinfo[i].claimeruname + "</td>\n" +
                        "                <td style=\"width: 120px;text-align: center\">" + financeinfo[i].reason + "</td>\n" +
                        "                <td style=\"width: 150px;text-align: center\">" + financeinfo[i].zhifutime.substring(0,10) + "</td>\n" +
                        "                <td style=\"width: 100px;text-align: center\">" + financeinfo[i].sumx + "</td>\n" +
                        "                <td style=\"width: 100px;text-align: center\">" + (financeinfo[i].typex==1?'支出':'收入') + "</td>\n" +
                        "                <td style=\"width: 100px;text-align: center\">" + financeinfo[i].balance + "</td>\n" +
                        "                <td style=\"width: 100px;text-align: center\">" + financeinfo[i].recorderuname + "</td>\n" +
                        "                <td style=\"width: 150px;text-align: center\">" + financeinfo[i].reasontime.substring(0,10) + "</td>\n" +
                        "                <td style=\"width: 120px;text-align: center\">\n" +
                        "                    <a href=\"#\" style=\"text-decoration: none;color: #216DF5\"" +
                        "onclick='edit1(" + JSON.stringify(financeinfo[i]) + ")'" +
                        ">编辑</a>&nbsp;&nbsp;\n" +
                        "                    <a href=\"#\" style=\"text-decoration: none;color: #8685F7\" onclick='deletex(" +financeinfo[i].id+
                        ")'>删除</a>\n" +
                        "                </td>\n" +
                        "            </tr>")
                } else {
                    $("#dongtaibiao").append("<tr class='d1' style=\"font-size: 14px;color: #2D2F33;\n" +
                        "                font-weight: 500;height: 50px;\n" +
                        "                background-color: #F4F7FD;\"" +
                        " id='" + financeinfo[i].id + "'" + ">\n" +
                        "                <td style=\"width: 100px;text-align: center\">" + financeinfo[i].claimeruname + "</td>\n" +
                        "                <td style=\"width: 120px;text-align: center\">" + financeinfo[i].reason + "</td>\n" +
                        "                <td style=\"width: 150px;text-align: center\">" + financeinfo[i].zhifutime.substring(0,10) + "</td>\n" +
                        "                <td style=\"width: 100px;text-align: center\">" + financeinfo[i].sumx + "</td>\n" +
                        "                <td style=\"width: 100px;text-align: center\">" + (financeinfo[i].typex==1?'支出':'收入') + "</td>\n" +
                        "                <td style=\"width: 100px;text-align: center\">" + financeinfo[i].balance + "</td>\n" +
                        "                <td style=\"width: 100px;text-align: center\">" + financeinfo[i].recorderuname + "</td>\n" +
                        "                <td style=\"width: 150px;text-align: center\">" + financeinfo[i].reasontime.substring(0,10) + "</td>\n" +
                        "                <td style=\"width: 120px;text-align: center\">\n" +
                        "                    <a href=\"#\" style=\"text-decoration: none;color: #216DF5\"" +
                        "onclick='edit1(" + JSON.stringify(financeinfo[i]) + ")'" +
                        ">编辑</a>&nbsp;&nbsp;\n" +
                        "                    <a href=\"#\" style=\"text-decoration: none;color: #8685F7\" onclick='deletex(" +financeinfo[i].id+
                        ")'>删除</a>\n" +
                        "                </td>\n" +
                        "            </tr>")
                }
            }

    }
    //分页样式与触发的动作
    function makepages(){
        //获取总个数  总页数
        $.ajax({
            url: ppath+"queryinfonum",
            type: "POST",
            async: false,
            contentType:"application/json;charset=UTF-8",
            data: JSON.stringify(financequeryvo),
            // data: user,
            dataType: "text",
            success: function (result) {
                total=result
            },
            error: function (res){
                // alert("网络错误")
            }
        })
        totalpage=Math.ceil(total/financequeryvo.limit)
        $(".pbt").remove()
        for(i=1;i<totalpage+1;i++){
            $(".pbtt").before("<div class=\"pbt\"" +"id='p"+i+"'"+
                ">\n" +
                "                    <a href=\"#\"" +"id='pa"+i+"'"+"onclick='topage("+i+")'"+
                ">"+i+"</a>\n" +
                "                </div>")
        }
        $("#p"+current).css("background-color","#2985F7")
        $("#pa"+current).css("color","#FFFFFF")
        $(".pbtt").text(current+"/"+totalpage+"页")
        $("#itemtotal").text(total)
        $("#itemstart").text((current-1)*limit+1)
        if(total==0){
            $("#itemstart").text(total)
        }
        $("#itemend").text(current*limit)
        if(current==totalpage || total==0){
            $("#itemend").text(total)
        }





    }
    //分页方法
    //上一页
    function prefix(){
        if(current!=1){
            current=current-1
            financequeryvo.current=current
            loaddata()
            makepages()
        }
    }
    //下一页
    function nextp(){
        if(current!=totalpage){
            current=current+1
            financequeryvo.current=current
            loaddata()
            makepages()
        }
    }
    //到具体页
    function topage(val){
        current=val
        financequeryvo.current=current
        loaddata()
        makepages()
    }
    //添加数据
    function adddata() {
        $.ajax({//GET请求通过用户id 获取用户信息
            url: ppath+"getalluser",
            type: "GET",
            async: false,
            dataType: "text",
            success: function (result) {
                users=JSON.parse(result)
                console.log('用户列表',users)
            },
            error: function (res){//请求异常时的回调
                alert("没有该用户")
            }
        });
        $(".adddata").show()
        $(".adddataform").show()
        $("#bxroptions").remove()
        for(var i=0;i<users.length;i++){
            if(users[i].type==1){
                $("#bxrselect").append("<option id='bxroptions' value='" +users[i].id+
                    "' >" +users[i].userName+ "</option>")
            }
        }
    }
    //提交新增
    function submitadd(){
        tbFinanceInfo.claimerUserId=$("#bxrselect").find("option:selected").val()
        tbFinanceInfo.reason=$("#reason").val()
        tbFinanceInfo.createTime=$("#createTime").val()
        tbFinanceInfo.sum=$("#sum").val()
        tbFinanceInfo.type=$("#type").find("option:selected").val()
        tbFinanceInfo.reasonTime=$("#reasontime").val()
        tbFinanceInfo.recorderUserId=$.cookie('userid')

        console.log("测试提交添加的表单参数：",tbFinanceInfo)
        if(tbFinanceInfo.createTime==''){
            alert("请输入收入/支出时间")
            return false
        }
        if(tbFinanceInfo.reasonTime==''){
            alert("请输入报销时间时间")
            return false
        }
        if(tbFinanceInfo.reason==''){
            alert("请输入报销事由")
            return false
        }
        if(tbFinanceInfo.sum==''){
            alert("请输入报销金额")
            return  false
        }
        //提交数据 (输入满足条件了，可以提交）
        $.ajax({
            url: ppath+"addfinanceinfo",
            type: "POST",
            async: false,
            contentType:"application/json;charset=UTF-8",
            data: JSON.stringify(tbFinanceInfo),
            // data: user,
            dataType: "text",
            success: function (result) {
                if(result){//添加成功
                    adddataclose()
                    financequeryvo.current=1
                    loaddata()
                    makepages()
                    tbFinanceInfo.claimerUserId=null
                    tbFinanceInfo.createTime=null
                    tbFinanceInfo.reason=""
                    tbFinanceInfo.reasonTime=null
                    tbFinanceInfo.recorderUserId=null
                    tbFinanceInfo.sum=""
                    tbFinanceInfo.type=2
                    alert("新增成功")

                }
            },
            error: function (res){
                // alert("网络错误")
            }
        })



    }
    //取消编辑
    function adddataclose() {
        $(".adddata").hide()
        $(".adddataform").hide()

    }
</script>
<style>
</style>
</html>